package other

import scala.io.Source

object CategoryFrequencyCounter {
  def main(args: Array[String]): Unit = {
    val fileName = "E:\\JSPproject\\Scallahomework\\src\\main\\scala\\data.txt"
    try {
      val lines = Source.fromFile(fileName).getLines().toList

      val categoryCounts = lines.map(line => line.split("\\\\00A"))
        .map(parts => parts(2))
        .groupBy(identity)
        .mapValues(_.size)

      categoryCounts.foreach { case (category, count) =>
        println(s"($category, $count)")
      }
    } catch {
      case e: Exception => println(s"Error reading file: ${e.getMessage}")
    }
  }
}